var prefix = jsctx + "/hlhtTenantOpenList";

var openPrice = (function () {
    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });
    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }

    function goBack() {
        window.history.back();
    }

    function updateHlhtTenantOpenPriceForOpenStation() {
        layer.open({
            type: 1,
            title: '互联价格批量调整',
            closeBtn: false,
            shade: 0.4,
            shift: 7,
            shadeClose: true,
            content: `<div style='width:350px;padding:10px;text-align: left'>
                        <div >
                        <span style="font-size: 16px">调整服务费:</span>
                        <input type="text" id="adjustValue" maxlength="4" onkeyup="this.value>=0?this.value=this.value:this.value=''" style="width: 100px;height: 30px;margin-left: 10px;text-align: center"  value="1"><span style="margin-left: 5px">元/度</span>
                        </div>
                        <span>说明：针对站点原始电价的服务费进行增加或是减少调整。如某站的原始服务费为0.6元/度，调整服务费为0.1，则调整后的互联服务费是0.7元/度。以该互联服务费+原基本电价作为推送价格给到互联方。</span>
                       </div>`,
            btn: ['确定', '取消'],
            yes: function (index) {//layer.msg('yes');    //点击确定回调
                if (!$("#adjustValue").val()) {
                    layer.msg("请输入服务费");
                    return;
                }
                layer.close(index);
                $.ajax({
                    url: prefix + "/updateHlhtTenantOpenPriceForOpenStation",
                    type: "post",
                    data: {
                        elecStationId: $("#elecStationId").val(),
                        tenantOpenId:$("#tenantOpenId").val(),
                        adjustValue:$("#adjustValue").val()

                    },
                    traditional:true,
                    success: function (data) {
                        layer.close(index);
                        if (data.status == 200) {
                            layer.msg(data.message);
                            goBack()
                        } else {
                            layer.msg(data.message);
                        }
                    }
                });
            },
        });

    }

    function save() {

        var dataArr = [];
        $(".elecStationPrice").each(function () {
                var obj = {}
                obj.openPriceId= $(this).find("input[name='openPriceId']").val();
                obj.openPriceAdjustValue= $(this).find("input[name='openPriceAdjustValue']").val();
                dataArr.push(obj)

        });
        var test = dataArr;
        $.ajax({
            cache: false,
            type: "POST",
            url: prefix + "/updateHlhtTenantOpenPrice",
            data:JSON.stringify(dataArr),
            dataType: "json",
            headers:{
                'Content-Type':'application/json;charset=UTF-8',
            },
            beforeSend: function () {
                isajaxsend = false
            },
            error: function (request) {
                parent.layer.alert("Connection error");
            },
            success: function (data) {
                if (data.status == 200) {
                    parent.layer.msg("操作成功");
                    window.history.back();
                } else {
                    parent.layer.alert(data.message)
                }
            },
            complete: function () {
                isajaxsend = false
            }
        });
    }


    $.fn.serializeObject = function() {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function() {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };
    return {
        goBack: goBack,
        reLoad: reLoad,
        updateHlhtTenantOpenPriceForOpenStation:updateHlhtTenantOpenPriceForOpenStation,
        save:save

    };
})();






